package com.seadragon.app.ksr.util;

import java.lang.reflect.Type;

import org.joda.time.LocalTime;

import com.fatboyindustrial.gsonjodatime.Converters;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class CustomConverters {

	public static GsonBuilder registerAll(GsonBuilder builder)
	  {
	   builder = Converters.registerAll(builder);
	   registerLocalTime(builder);
	    return builder;
	  }
	
	  /**
	   * Registers the {@link LocalTime} converter.
	   * @param builder The GSON builder to register the converter with.
	   * @return A reference to {@code builder}.
	   */
	  public static GsonBuilder registerLocalTime(GsonBuilder builder)
	  {
	    if (builder == null) { throw new NullPointerException("builder cannot be null"); }

	    final Type type = new TypeToken<LocalTime>(){}.getType();
	    builder.registerTypeAdapter(type, new CustomLocalTimeConverter());

	    return builder;
	  }
}
